<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'

const animationDuration = 6000

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
            text: '余额-企业性质',
            
        },
        color:['#49b1dd','#fc9c42'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow' 
          }
        },
        xAxis: [{
          type: 'category',
          
          data: ['国有 投资', '国有 控股', '集体', '民营', '中外 合资', '合营',"个体 工商户","事业团体","其他"].map(function(str){
              return str.replace(' ', '\n')
          }),
          axisTick: {
            alignWithLabel: true
          },
          axisLabel:{
              interval:0
          }
        }
        
        ],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          }
        }],
        series: [
            {   name: 'pagea',
                barWidth : 10,
                data: [100, 932, 901, 500, 1290, 1330, 1320,820,820],
                type: 'bar',
                smooth: true,
                itemStyle: { 
                        emphasis: {
                            barBorderRadius: 30
                        },
                        normal: {
                            barBorderRadius:[10, 10, 10, 10],
                            lineStyle:{  
                                color:  '#49b1dd'
                            } 
                        },
                        
                }
            },
             {  name: 'pageb',
                barWidth : 10,
                data: [820, 932, 901, 934, 1290, 150, 1320,820,820],
                type: 'bar',
                smooth: true,
                itemStyle: { 
                        emphasis: {
                            barBorderRadius: 30
                        },
                        normal: {
                            barBorderRadius:[10, 10, 10, 10],
                            lineStyle:{  
                                color: '#fc9c42' 
                            } 
                        }
                       
                }
            }
            
        
        ]
      })
    }
  }
}
</script>
